package com.example.student_systeam.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.student_systeam.entity.Student;
import com.example.student_systeam.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@Service
public class StudentService {

    @Autowired
    public StudentMapper studentMapper;


    public List<Student> findAllStudent(){
        return studentMapper.selectList(null);
    }

    public Integer insertStudent(Student student){
        return (studentMapper.insert(student));
    }

    public void updateStudent(Student student){
        UpdateWrapper<Student>updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("name",student.getName());

        Student student1 = studentMapper.selectOne(updateWrapper);
        student1.setAge(student.getAge());

        studentMapper.update(student1,updateWrapper);

    }

    public Integer deleteStudentByName(Student student){
        HashMap<String, Object>map = new HashMap<>();
        map.put("name",student.getName());
        int sum = studentMapper.deleteByMap(map);
        return sum;
    }


    public String ff(){
        return "hhh";
    }
}
